package logic

import (
	"context"

	"wxapi/internal/services"
	"wxapi/internal/svc"
	"wxapi/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetDoctorItemsLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGetDoctorItemsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetDoctorItemsLogic {
	return &GetDoctorItemsLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetDoctorItemsLogic) GetDoctorItems(req *types.GetDoctorItemsReq) (resp *types.GetDoctorItemsResp, err error) {
	items, err := services.GetDoctorItems(l.ctx, l.svcCtx, req.DoctorID)
	if err != nil {
		return nil, err
	}

	resp = &types.GetDoctorItemsResp{
		List: make([]types.DoctorItem, 0),
	}
	for _, item := range items {
		i := types.DoctorItem{
			ID:       item.SkillId,
			Duration: item.Duration,
			Price:    int64(item.Price.InexactFloat64()),
		}
		if item.Skill != nil {
			i.Name = item.Skill.SkillName
		}
		resp.List = append(resp.List, i)
	}

	return
}
